var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-39628581-1']);
(function() {
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
(function() {
// Localize jQuery variable
var jQuery;
var bs_base_url;
bs_base_url = "http://www.bugscore.com/";
var amazon_url = "https://s3-eu-west-1.amazonaws.com/bugscoreapi/";
/******** Load jQuery if not present *********/
if (window.jQuery === undefined || window.jQuery.fn.jquery !== '1.6.4') {
var script_tag = document.createElement('script');
script_tag.setAttribute("type","text/javascript");
script_tag.setAttribute("src",
"https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js");
if (script_tag.readyState) {
script_tag.onreadystatechange = function () { // For old versions of IE
if (this.readyState == 'complete' || this.readyState == 'loaded') {
scriptLoadHandler();
}
};
} else {
script_tag.onload = scriptLoadHandler;
}
(document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);
} else {
jQuery = window.jQuery;
main();
}
/******** Called once jQuery has loaded ******/
function scriptLoadHandler() {
jQuery = window.jQuery.noConflict(true);
main();
}
function scoreHandler(data,bs_img_size,bs_key,bs_current_url,bs_widget_key,widget_load_url,bs_profile_id){
jQuery('<div/>', {
id: 'bs_image_holder_'+bs_img_size+'_'+bs_key,
'class': 'bs_image_holder_'+bs_img_size
}).appendTo(jQuery('#bs-widget-container-'+bs_key));
if(data.scoredata!="")
{
jQuery('<div/>', {
id: 'bs_score_holder_'+bs_img_size+'_'+bs_key,
'class': 'bs_score_holder_'+bs_img_size
}).appendTo(jQuery('#bs-widget-container-'+bs_key));
jQuery('<div/>', {
id: 'bs_score_box_'+bs_img_size+'_'+bs_key,
'class': 'bs_score_box_'+bs_img_size
}).appendTo(jQuery('#bs_score_holder_'+bs_img_size+'_'+bs_key));
}
jQuery('<img/>', {
src: data.imageurl,
title: data.imagetitle,
height: data.imageheight,
width: data.imagewidth,
load: function(e){
_gaq.push(['_trackEvent', 'APIReports', 'APIButtonLoad', widget_load_url, parseInt(bs_key)]);
},
click: function(e){
var title = "bugscore";
var w;
var h;
if(bs_profile_id!="")
{
w=433;
h=450;
}
else
{
w=342;
h=432;
}
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
if(data.profileid!="")
{
var pageURL = bs_base_url+ "widget_score_profile.php?profile_id="+data.profileid+"&bs_widget_key="+bs_widget_key;
}
else if(data.article!="")
{
var pageURL = bs_base_url+ "widget_score_article.php?article_url="+bs_current_url+"&bs_widget_key="+bs_widget_key;
}
else
{
var pageURL = bs_base_url+ "widget_profiles.php?widget_key="+bs_widget_key;
}
window.open (pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
}
}).appendTo(jQuery('#bs_image_holder_'+bs_img_size+'_'+bs_key));
if(data.scoredata!="")
{
jQuery('#bs_score_box_'+bs_img_size+'_'+bs_key).html(data.scoredata);
}
}
function main() {
jQuery(document).ready(function($) {
/******* Load CSS *******/
var css_url = amazon_url + "css/widget.css?v=1.2";
var css_link = $("<link>", {
rel: "stylesheet",
type: "text/css",
href: css_url
});
css_link.appendTo('head');
$(".bs-widget-container").each(function() {
var bs_profile_id = "";
var bs_widget_key = "";
var bs_key = "";
var bs_img_size = "small";
bs_widget_key = $(this).attr("id").replace("bs-widget-container-","");
if(bs_widget_key!="")
{
bs_key = bs_widget_key;
}
/******* Load HTML *******/
bs_current_url = window.location.href;
if(bs_current_url.indexOf('#')>0)
{
bs_current_url = bs_current_url.substring(0, bs_current_url.indexOf('#'));
}
if(bs_current_url.match(/http:\/\//))
{
bs_current_url = bs_current_url.substring(7);
}
if(bs_current_url.match(/^www\./))
{
bs_current_url = bs_current_url.substring(4);
}
var widget_load_url = document.domain
if(widget_load_url.match(/^www\./))
{
widget_load_url = widget_load_url.substring(4);
}
var success = false;
var jsonp_url = "https://s3-eu-west-1.amazonaws.com/bugscoreapi/widget_"+ bs_widget_key +".json";
var errorTimeout = setTimeout(function() {
if(!success)
{
var jsonp_url = bs_base_url + "components/widget_ui_handler.php?widget_key=" + bs_widget_key + "&img_size=small&article_url="+bs_current_url+"&callback=?";
$.getJSON(jsonp_url, function(data) {
scoreHandler(data,bs_img_size,bs_key,bs_current_url,bs_widget_key,widget_load_url,bs_profile_id)
});
}
}, 5000);
$.ajax({
type: 'GET',
url: jsonp_url,
dataType: 'jsonp',
jsonpCallback: 'content',
cache: false
}).done(function (data) {
success = true;
clearTimeout(errorTimeout);
scoreHandler(data,bs_img_size,bs_key,bs_current_url,bs_widget_key,widget_load_url,bs_profile_id)
})
});
});
}
})();